/*
 * Created on 26-Apr-05
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.one.stone.soup.grfxML.plugin.system;

import java.io.File;

import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.stringhelper.FileNameHelper;

public class GrfxMLDropHandler implements DropHandler {

	public GrfxMLDropHandler()
	{
	}

	/* (non-Javadoc)
	 * @see org.one.stone.soup.grfxML.plugin.system.DropHandler#matches(java.lang.String)
	 */
	public boolean matches(String name,int x,int y) {
		if(
			FileNameHelper.getExt(name).equals("grfxml")
		)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see org.one.stone.soup.grfxML.plugin.system.DropHandler#handle(java.lang.String)
	 */
	public boolean handle(String name,GrfxMLEngine engine,int x,int y) {

		try{
			String fileExtension = FileNameHelper.getExt(name).toLowerCase();

			if(fileExtension.equals("grfxml"))
			{
				if(name.indexOf("http://")==-1)
				{
					name = new File(name).toURL().toString();
				}

				engine.getAPI().load( name );
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return true;
	}
}
